﻿#Include RichText.ahk

g := Gui('AlwaysOnTop')
g.SetFont('s14', 'consolas') ; 由于粗糙的宽度计算，需要使用等宽字体，且不适合宽字符

; ======== 一
t := [
  TextData('Test', 'red', 'black', 'strike'),
  TextData('T`nest编辑A0123', 'green', 'd2d2ff', 'bold'), ; 中文粗体样式会导致部分字符无法显示，原因不明
  TextData('Te世界s`nT01234', 'green', 'bde6b8', 'underline'),
  TextData('Test012345`n6789', 'green', 'd2bab2', 'italic'),
  TextData.of('`n`nDONE')
]

; 硬换行，指字符中的 `n ;软换行，指自动换行
rt := RichText(g, 10, 10, 160, t, { softBreak: true, hardBreak: true, bg: '00ff2a', bc: '\', debug: 1 })
rt.GetPos(, &y := 0, , &h := 0)


a:: rt.Hide()
d:: rt.Show()
; ======== 二
warn := {
  bg: 'yellow',
  fg: 'red',
  ex: 'bold'
}
t1 := [
  TextData.of('This is a'),
  TextData.of(' Sample ', warn),
  TextData.of('of RichText.ahk'),
  TextData('`nVersion 2.0`n', '797979', 'e9e9e9', 'italic'),
  TextData.of('
  (
  Explore uncertain by upon now for rare farther. Of with head for here. 
  Tis fiend nevermore maiden a my one, oer hesitating evermore the but now this gave i. 
  Raven a ghastly perfumed of nepenthe discourse and.
  On i then muttered on angels door raven, demons or clasp farther the quoth.
  Swung the forgiveness just surely pallas then. Back home.
  )')
]

rt1 := RichText(g, 10, y + h + 10, 380, t1, { softBreak: true, hardBreak: true, bg: 'a3e5e0', bc: '', debug: 0 })
rt1.GetPos(, &y := 0, , &h := 0)
; MsgBox rt1.text
; ======== 三
t2 := [
  TextData.of('A`nD', warn).OnEvent('click', _ => MsgBox('lc' _.Text)).OnEvent('context', _ => MsgBox('rc' _.Text)),
  TextData('    B', 'ffffff', '0095ff', '').OnEvent('context', _ => MsgBox('rc' _.Text)),
]

; ===== 不指定背景色，则使用前一个字符的颜色
rt2 := RichText(g, 10, y + h + 10, 160, t2, { softBreak: false, hardBreak: true, bc: '<', debug: 1 })

g.Show('w400 h600')
g.OnEvent('Close', (*) => ExitApp())